package IOStreamTest.ObjectStream;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;

/*
将多个对象反序列化
 */
public class ObjectInputStreamTest2 {
    public static void main(String[] args) {
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream("persons"));
            Object list = ois.readObject();
            if(list instanceof List){
                ArrayList<Person> list1 =(ArrayList<Person>)list;
                for(Person p : list1){
                    System.out.println(p);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally{
            if (ois != null) {
                try {
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
